home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / StringToDateAndSecs.c < prev    next >
Text File  |  1995-07-26  |  1KB  |  48 lines

  1. /*
  2. StringToDateAndSecs.c
  3. Reads date such as "6/30/91", loads date structure, and returns secs since 1/1/1904.
  4. Returns NAN if date could not be read.
  5.  
  6.  
  7. HISTORY:
  8. 7/27/91 dgp    wrote it
  9. 8/5/91    dgp    made compatible with MPW C 3.2
  10. 8/24/91    dgp    Made compatible with THINK C 5.0.
  11. 12/13/92 dgp Removed obsolete support for THINK C 4.
  12. 5/28/94 dgp Renamed from "StringToDate" to "StringToDateAndSecs" to avoid
  13. conflict with Apple's new Universal Headers. Thanks to Bob Dougherty 
  14. (wolfgang@cats.ucsc.edu) for reporting the incompatibility.
  15. */
  16. #include "VideoToolbox.h"
  17. //#include <Script.h>
  18. double StringToDateAndSecs(char *string,DateTimeRec *datePtr);
  19.  
  20. double StringToDateAndSecs(char *string,DateTimeRec *datePtr)
  21. {
  22.     LongDateRec longDate;
  23.     LongDateCvt longSecs;
  24.     double secs;
  25.     static DateCacheRecord theCache;
  26.     static Boolean firstTime=1;
  27.     int error;
  28.     long used;
  29.     
  30.     longDate.ld.era=longDate.ld.year=longDate.ld.month=longDate.ld.day=0;
  31.     longDate.ld.hour=longDate.ld.minute=longDate.ld.second=longDate.ld.dayOfWeek=0;
  32.     if(firstTime){
  33.         InitDateCache(&theCache);
  34.         firstTime=0;
  35.     }
  36.     error=String2Date(string,strlen(string),&theCache,&used,&longDate);
  37.     *datePtr=longDate.od.oldDate;
  38.     if(error)return NAN;
  39.     LongDate2Secs(&longDate,(LongDateTime *)&longSecs);
  40.     secs=HiWord(longSecs.hl.lHigh);
  41.     secs*=(double)0x10000;
  42.     secs+=(unsigned)LoWord(longSecs.hl.lHigh);
  43.     secs*=(double)0x10000;
  44.     secs+=(unsigned)HiWord(longSecs.hl.lLow);
  45.     secs*=(double)0x10000;
  46.     secs+=(unsigned)LoWord(longSecs.hl.lLow);
  47.     return secs;
  48. }